rust-numpy
Rust bindings for the NumPy C-API.
API documentation
Requirements
- Rust >= 1.48.0
- Basically, our MSRV follows the one of PyO3
- Python >= 3.7
- Python 3.6 support was dropped from 0.16
- Some Rust libraries
- ndarray for Rust-side matrix library
- PyO3 for Python bindings
- And more (see Cargo.toml)
- numpy installed in your Python environments (e.g., via
pip install numpy
)- We recommend
numpy >= 1.16.0
, though older versions may work
- We recommend
Example
Write a Python module in Rust
Please see the simple example for how to get started.
There are also examples using ndarray-linalg and rayon.
[]
= "rust_ext"
= ["cdylib"]
[]
= { = "0.16", = ["extension-module"] }
= "0.16"
use ;
use ;
use ;
Execute a Python program from Rust and get results
[]
= "numpy-test"
[]
= { = "0.16", = ["auto-initialize"] }
= "0.16"
use PyArray1;
use ;
Dependency on ndarray
This crate uses types from ndarray
in its public API. ndarray
is re-exported
in the crate root so that you do not need to specify it as a direct dependency.
Furthermore, this crate is compatible with multiple versions of ndarray
and therefore depends
on a range of semver-incompatible versions, currently >= 0.13, < 0.16
. Cargo does not
automatically choose a single version of ndarray
by itself if you depend directly or indirectly
on anything but that exact range. It can therefore be necessary to manually unify these dependencies.
For example, if you specify the following dependencies
= "0.16"
= "0.13"
this will currently depend on both version 0.13.1
and 0.15.3
of ndarray
by default
even though 0.13.1
is within the range >= 0.13, < 0.16
. To fix this, you can run
to achieve a single dependency on version 0.13.1
of ndarray
.
Contributing
We welcome issues and pull requests.
PyO3's Contributing.md is a nice guide for starting.
Also, we have a Gitter channel for communicating.